/**
 * Created by chenzheyu on 2017/4/10.
 */
$(function () {
    var limit = 20;
    var SEOval = '';

    function xin() {
        $.ajax({
            url: ctx + '/rentorder/selectRentOrdersCount',
            type: 'GET',
            success: function (data) {
                var text = data.split(',');
                var li = $('.CustomTabs ul li');
                if (text[0] > 0) {
                    if (li.eq(0).find('.CustomBadge').length > 0) {
                        li.eq(0).find('.CustomBadge').remove();
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    } else {
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    }
                }
                if (text[1] > 0) {
                    if (li.eq(7).find('.CustomBadge').length > 0) {
                        li.eq(7).find('.CustomBadge').remove();
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    } else {
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    }
                }
                if (text[2] > 0) {
                    if (li.eq(8).find('.CustomBadge').length > 0) {
                        li.eq(8).find('.CustomBadge').remove();
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    } else {
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    }
                }
            }
        })
    }

    xin();
    setInterval(function () {
        xin()
    }, 60000);
    function dispatchCar(data, index) {
        console.log(data)
        var QuCar = {
            data: {
                Title: '分配车辆',
                Content: '',
                OkChange: function (e,Rmove) {
                    if($('.CustomModalBox').data('carId')){
                        $.ajax({
                            url: ctx + '/rentorder/dispatchCar',
                            data: {
                                id: data.content[index].id,
                                carId: $('.CustomModalBox').data('carId'),
                                plateNo: $('.CustomModalBox').data('plateNo'),
                                vehicle: $('.CustomModalBox').data('vehicle')
                            },
                            type: 'POST',
                            success: function (data) {
                                if (data.message == '派车成功') {
                                    $('body').Overlays({data: {text: '派车成功！', state: 'Ok'}});
                                    ConfirmedOrder(1, SEOval);
                                    Rmove()
                                } else {
                                    $('body').Overlays({data: {text: '派车失败，请稍后重试！', state: 'No'}});
                                    ConfirmedOrder(1, SEOval);
                                    Rmove()
                                }
                            }
                        })
                    }else {
                        $('body').Overlays({data: {text: '请选择车辆！', state: 'No'}});
                    }

                }
            },
            OKHide:true
        };
        var limit = 10;
        var brandId = '';
        var plateNo = '';
        var vehicleId = data.content[index].vehicle;
        var shopID = data.content[index].shopId;
        var allotCar = $('<div class="allotCar"></div>');
        allotCar.append('<div class="allotCarNav"><span>品牌-车系：</span><input type="text" class="carType" placeholder="点击选择品牌及车系" readonly><span>车牌号：</span><input class="plateNo" type="text" placeholder="请输入车牌号"><span class="ActionSEO"></span></div><div class="allotCarOrder"></div>');
        var pids = ''
            $.ajax({
                url: ctx + '/rentcontent/selectAllProperty',
                type: 'GET',
                async: false,
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].seq === 4) {
                            pids = data[i].id
                        }
                    }
                }
            });
        $.ajax({
            url: ctx + '/rentcontent/selectContentByPid',
            data: {
                pid: pids
            },
            success: function (data) {
            	console.log(data)
                var brandSelect = {
                    data: [],
                    onChange: function () {
                    }
                };
                for (var i = 0; i < data.length; i++) {
                    (function () {
                        var index = i;
                        brandSelect.data.push({name: data[index].contentName, Val: data[index].id})
                    })()
                }
                allotCar.find('.brandSelect').DownPullSelect(brandSelect)
            }
        });
        allotCar.find('.carType').on('click', function () {
            var vehicleIdOption = {
                data: {
                    Title: '选择车系',
                    Content: '',
                    OkChange: function (e, Remove) {
                        if (allotCar.find('.carType').data('data')) {
                            var data = allotCar.find('.carType').data('data');
                            brandId = data.CarBrandId;
                            vehicleId = data.vehicleId;
                            allotCar.find('.carType').val(data.CarBrandName + ' - ' + data.CarSeriesName);
                            Remove()
                        } else {
                            $('body').Overlays({data: {text: '请选择一个车系！', state: 'No'}})
                        }
                    }
                },
                OKHide: true
            };
            var vehicleIdContent = $('<div class="vehicleIdContent"></div>');
            $.ajax({
                url: ctx + '/rentcontent/selectContentByPid',
                data: {
                    pid: pids
                },
                type: 'GET',
                success: function (data) {
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            (function () {
                                var index = i;
                                var val = $('<div class="Brand"></div>').html('<div class="BrandName">' + data[index].contentName + '</div><div class="Vehicle CustomClear"></div>');
                                var Id = data[index].id;
                                var Name = data[index].contentName;
                                $.ajax({
                                    url: ctx + '/rentvehicle/findVehicleByparams',
                                    data: {
                                        shopId: shopID,
                                        brandId: data[index].id
                                    },
                                    type: 'GET',
                                    success: function (data) {
                                        if(data.content.length>0){
                                            for (var i = 0; i < data.content.length; i++) {
                                                (function () {
                                                    var index = i;
                                                    var item = $('<label class="CustomClear"></label>');
                                                    item.append('<input type="radio" name="Vehicle" value="' + data.content[i].id + '"><span>' + data.content[i].name + '</span>');
                                                    item.on('click', function () {
                                                        var datas = {
                                                            vehicleId: data.content[index].id,
                                                            CarSeriesId: data.content[index].id,
                                                            CarSeriesName: data.content[index].name,
                                                            CarBrandId: Id,
                                                            CarBrandName: Name
                                                        };
                                                        allotCar.find('.carType').data('data', datas)
                                                    });
                                                    val.find('.Vehicle').append(item)
                                                })()
                                            }
                                        }else {
                                            val.find('.Vehicle').append('此品牌下未添加车系！')
                                        }
                                    }
                                });
                                vehicleIdContent.append(val)
                            })()
                        }
                    }
                }
            });
            vehicleIdOption.data.Content = vehicleIdContent;
            $('body').ModalBox(vehicleIdOption);
        });
        allotCar.find('.ActionSEO').ActionButtons({
            data: '查询', onChange: function () {
                plateNo = allotCar.find('.plateNo').val();
                CarOrder(1, brandId, plateNo, shopID, vehicleId);
            }
        });
        function CarOrder(page, brandId, plateNo, shopID, vehicleId) {
            $.ajax({
                url: ctx + '/rentvehicle/findById',
                type: "GET",
                data: {id:vehicleId},
                success:function (data) {
                    var data=data.data;
                    console.log(data)
                    allotCar.find('.carType').val(data.brandName+'-'+data.name)
                }
            })
            $.ajax({
                url: ctx + '/rentcar/findCar',
                data: {
                	state:0,
                	isGrounding:1,
                    param: plateNo,
                    shopId: shopID,
                    vehicleId: vehicleId,
                    limit: limit,
                    'pager.offset': (page - 1) * limit
                },
                success: function (data) {
                    var allotCarOrder = {
                        data: {
                            Thead: {
                                action: '选择',
                                name: '车辆名称',
                                rent: '租金',
                                deposit: '押金',
                                brand: '品牌',
                                vehicle:'车系',
                                plateNo: '车牌号',
                                transmission: '变速箱',
                                type: '车型',
                                displacement: '排量',
                                seat: '座位数',
                                limit: '限行'
                            },
                            Tbody: []
                        }
                    };
                    for (var i = 0; i < data.content.length; i++) {
                        (function () {
                            var index = i;
                            var val = {
                                action: '',
                                name: data.content[index].rentCar.carName,
                                rent: data.content[index].vehicle.rent,
                                deposit: data.content[index].vehicle.illegalDeposit,
                                brand: data.content[index].vehicle.brandName,
                                vehicle:data.content[index].vehicle.name,
                                plateNo: data.content[index].car.plateNo,
                                transmission: data.content[index].vehicle.transmission,
                                type: data.content[index].vehicle.type,
                                displacement: data.content[index].vehicle.displacement,
                                seat: data.content[index].vehicle.seat,
                                limit: data.content[index].rentCar.limit
                            };

                            switch (data.content[index].rentCar.limit) {
                                case 0:
                                    val.limit = '不限行';
                                    break;
                                case 1:
                                    val.limit = '星期一';
                                    break;
                                case 2:
                                    val.limit = '星期二';
                                    break;
                                case 3:
                                    val.limit = '星期三';
                                    break;
                                case 4:
                                    val.limit = '星期四';
                                    break;
                                case 5:
                                    val.limit = '星期五';
                                    break;
                                case 6:
                                    val.limit = '星期六';
                                    break;
                                case 7:
                                    val.limit = '星期日';
                                    break;
                            }

                            var RadioActionButtonsOption = $('<span class="RadioActionButtonsOption"></span>');
                            RadioActionButtonsOption.RadioActionButtons({
                                data: {
                                    name: 'allotCar'
                                },
                                onChange: function () {
                                    $('.CustomModalBox').data({
                                        'carId': data.content[index].rentCar.id,
                                        'plateNo': data.content[index].car.plateNo,
                                        'vehicle': data.content[index].vehicle.id
                                    })
                                }
                            });
                            val.action = RadioActionButtonsOption;
                            allotCarOrder.data.Tbody.push(val)
                        })()
                    }
                    allotCar.find('.allotCarOrder').Order(allotCarOrder);
                    var PagingMdOption = {
                        data: {
                            rows: limit,
                            nowrows: page,
                            Pages: '',
                            total: data.totalElements,
                            change: function (index) {
                                CarOrder(1, brandId, plateNo, shopID, vehicleId);
                            }
                        }
                    };
                    allotCar.find('.allotCarOrder').PagingMd(PagingMdOption)
                }
            });
        }

        CarOrder(1, brandId, plateNo, shopID, vehicleId);
        QuCar.data.Content = allotCar;
        $('body').ModalBox(QuCar);
    }

    function ConfirmedOrder(page, inquireVal) {
        var ConfirmedOrderOptin = {
            plateNoOrPassengerPhone: inquireVal || '',
            status: 10,
            'limit': limit,
            'pager.offset': (page - 1) * limit
        };
        $.ajax({
            url: ctx + '/rentorder/selectRentOrders',
            type: "GET",
            data: ConfirmedOrderOptin,
            success: function (data) {
                var option = {
                    data: {
                        Thead: {
                            PullDownAction: '操作',
                            OrderNumber: "单号",
                            totalFee:'总金额',
                            payed: '租金',
                            Store: "门店",
                            RetrievingMeans: "取车地址",
                            ReturnType: "还车地址",
                            bookTime: "预约时间",
                            HireTime: "还车时间",

                            // ReturnTime: "还车时间",
                            // ResidueTime: "剩余时间",
                            ClientName: "客户名称",
                            ClientPhone: "客户电话",
                            Car: "车辆号牌",
                            CarType: "车辆类型",
                            // RentalStandard: "租金标准",
                            Prepayment: "租车押金",
                            ViolationMoneys: "违章押金",
                            // PrepayMoney: "预授金额",
                            SubordinateCompanies: "所属公司",
                            Remark: "备注"
                        },
                        Tbody: []
                    }
                };
                // var PresentTimestamp=Date.parse((new Date())/1000);

                for (var i = 0; i < data.content.length; i++) {
                    (function (j) {
                        var index = j;
                        var val = {
                            id: data.content[index].id,
                            PullDownAction: {
                                data: []
                            },
                            OrderNumber: data.content[index].orderNo,
                            totalFree:data.content[i].totalFee,
                            payed:'',
                            Store: data.content[index].shopName,
                            RetrievingMeans: data.content[index].takeCarWay == 1 ? data.content[index].startAddress : "门店自取",
                            ReturnType: data.content[index].backCarWay == 1 ? data.content[index].endAddress : '门店自还',
                            bookTime: $().Timestamp.TimestampDate(data.content[index].bookTime),
                            HireTime: $().Timestamp.TimestampDate(data.content[index].rentTime),

                            // ResidueTime: $().Timestamp.DayCalculate(data.content[index].backCarTime-PresentTimestamp),
                            ClientName: data.content[index].passengerName,
                            ClientPhone: data.content[index].passengerPhone,
                            Car: data.content[index].plateNo,
                            CarType: data.content[index].category,
                            RentalStandard: data.content[index].RentalStandard,
                            Prepayment: data.content[index].prepayRent,
                            // ViolationMoneys: data.content[index].peccancyForegift,
                            // PrepayMoney: data.content[index].PrepayMoney,
                            SubordinateCompanies: data.content[index].companyName,
                            Remark: data.content[index].memo
                        };

                        if (data.content[index].carId) {
                            if (data.content[index].takeCarWay == 0) {
                                val.PullDownAction['Default'] = {
                                    name: '取车',
                                    action: function (e) {
                                        var qucheOption = {
                                            id: data.content[index].id
                                        };
                                        var QuCar = {
                                            data: {
                                                Title: '取车提示',
                                                Content: '您确定要取车吗？',
                                                OkChange: function () {
                                                    $.ajax({
                                                        url: ctx + '/rentorder/server',
                                                        data: qucheOption,
                                                        type: 'POST',
                                                        success: function (data) {
                                                            if (data.message == '订单状态修改成功') {
                                                                new $().Overlays({data: {text: '取车成功！', state: 'Ok'}});
                                                                ConfirmedOrder(1)
                                                            } else {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '取车失败，请稍后再试！',
                                                                        state: 'No'
                                                                    }
                                                                });
                                                            }
                                                        }
                                                    })
                                                }
                                            }
                                        };
                                        $('body').ModalBox(QuCar);
                                    }
                                };
                                val.PullDownAction.data.push({
                                    name: '查看', action: function () {
                                        window.location.href = ctx + '/rentorder/orderinfo?id=' + data.content[index].id;
                                    }
                                });
                            } else if (data.content[index].takeCarWay == 1) {
                                val.PullDownAction['Default'] = {
                                    name: '取车',
                                    action: function (e) {
                                        var qucheOption = {
                                            id: data.content[index].id
                                        };
                                        var QuCar = {
                                            data: {
                                                Title: '取车提示',
                                                Content: '您确定要取车吗？',
                                                OkChange: function () {
                                                    $.ajax({
                                                        url: ctx + '/rentorder/server',
                                                        data: qucheOption,
                                                        type: 'POST',
                                                        success: function (data) {
                                                            if (data.message == '订单状态修改成功') {
                                                                new $().Overlays({data: {text: '取车成功！', state: 'Ok'}});
                                                                ConfirmedOrder(1)
                                                            } else {
                                                                new $().Overlays({
                                                                    data: {
                                                                        text: '取车失败，请稍后再试！',
                                                                        state: 'No'
                                                                    }
                                                                });
                                                            }
                                                        }
                                                    })
                                                }
                                            }
                                        };
                                        $('body').ModalBox(QuCar);
                                    }
                                };
                                // val.PullDownAction.data.push({
                                //     name: '派单',
                                //     action: function (e) {
                                //         var index=e.parent().parent().parent().parent().data();
                                //
                                //
                                //         $.ajax({
                                //             url:'paidan.json',
                                //             type:'GET',
                                //             success:function () {
                                //                 var paidan={
                                //                     data:{
                                //                         Title:'派单',
                                //                         Content:null,
                                //                         OkChange:function () {
                                //
                                //                         }
                                //                     }
                                //                 };
                                //                 var HTML='<div class="Input">'+
                                //                     '<div class="List"><div class="name">客户姓名：</div><span class="Val">'+'陈哲宇'+'</span></div>'+
                                //                     '<div class="List"><div class="name">客户电话：</div><span class="Val">'+'18108162771'+'</span></div>'+
                                //                     '<div class="List"><div class="name">取车地址：</div><span class="Val">'+'成都市'+'</span></div>'+
                                //                     '<div class="List"><div class="name">还车地址：</div><span class="Val">'+'成都市'+'</span></div>'+
                                //                     '<div class="List"><div class="name">取车时间：</div><span class="Val">'+'2018-1205'+'</span></div>'+
                                //                     '<div class="List"><div class="name">还车时间：</div><span class="Val">'+'2016-1025'+'</span></div>';
                                //                 paidan.data.Content=HTML;
                                //                 $('body').ModalBox(paidan);
                                //                 var  MidContents= $('.MidContent');
                                //                 MidContents.append('<div class="LiteTitle CustomClear">' +
                                //                     '<h3>推荐服务人员 </h3>' +
                                //                     '<div class="line"><div class="LiteSEO">' +
                                //                   '<input type="text" placeholder="请输入电话/姓名/工号">' +
                                //                   '<button class="LiteSEOButton">查询</button>' +
                                //                   '</div></div>' +
                                //                     '</div>');
                                //               //   var SEO='<div class="LiteSEO">' +
                                //               //       '<input type="text" placeholder="请输入电话/姓名/工号">' +
                                //               //       '<button class="LiteSEOButton">查询</button>' +
                                //               //       '</div>';
                                //               // MidContents.append(SEO)
                                //                 WaiterOrder();
                                //                 function WaiterOrder() {
                                //                     $.ajax({
                                //                         url:'json.json',
                                //                         success:function (data) {
                                //                             var HTMLOrder=$('<div class="WaiterOrder"></div>');
                                //                             var HTMLOrderVal={
                                //                                 data:{
                                //                                     Thead:{
                                //                                         PullDownAction:'操作',
                                //                                         WaiterName:'陈哲宇',
                                //                                         WaiterNumber:12456,
                                //                                         WaiterPhone:18108162771
                                //                                     },
                                //                                     Tbody:[
                                //                                         {
                                //                                             id:1,
                                //                                             ButtonAction:{
                                //                                                 name:'指派',
                                //                                                 Action:function () {
                                //                                                     // console.log(22213)
                                //                                                 }
                                //                                             },
                                //                                             WaiterName:'陈哲宇',
                                //                                             WaiterNumber:12456,
                                //                                             WaiterPhone:18108162771
                                //                                         },
                                //                                         {
                                //                                             id:1,
                                //                                             ButtonAction:{
                                //                                                 name:'指派',
                                //                                                 Action:function () {
                                //                                                     // console.log('dasdasd')
                                //                                                 }
                                //                                             },
                                //                                             WaiterName:'陈哲宇',
                                //                                             WaiterNumber:12456,
                                //                                             WaiterPhone:18108162771
                                //                                         },
                                //                                         {
                                //                                             id:1,
                                //                                             ButtonAction:{
                                //                                                 name:'指派',
                                //                                                 Action:function () {
                                //                                                     // console.log('大家萨克贷记卡了')
                                //                                                 }
                                //                                             },
                                //                                             WaiterName:'陈哲宇',
                                //                                             WaiterNumber:12456,
                                //                                             WaiterPhone:18108162771
                                //                                         }
                                //                                     ]
                                //                                 }
                                //                             };
                                //
                                //                             HTMLOrder.Order(HTMLOrderVal);
                                //
                                //                             MidContents.append(HTMLOrder);
                                //
                                //                             var PagingOption={
                                //                                 data: {
                                //                                     rows: 20,
                                //                                     nowrows: 1,
                                //                                     Pages: 5,
                                //                                     total:100,
                                //                                     change: function (index) {
                                //                                         // console.log(index);
                                //                                         // console.log(PagingOption);
                                //                                         HTMLOrder.remove();
                                //                                         PagingModule.remove();
                                //                                         WaiterOrder();
                                //
                                //                                     }
                                //                                 }
                                //                             };
                                //                             var PagingModule=$('<div class="PagingModule"></div>');
                                //                             PagingModule.PagingMd(PagingOption);
                                //                             MidContents.append(PagingModule);
                                //                         }
                                //                     });
                                //                 }
                                //
                                //
                                //
                                //             }
                                //         })
                                //     }
                                // })
                            }
                            val.PullDownAction.data.push({
                                name: '销单',
                                action: function (e) {
                                    var QuCar = {
                                        data: {
                                            Title: '销单提示',
                                            Content: '你确定要销单吗？',
                                            OkChange: function () {
                                                $.ajax({
                                                    url: ctx + '/rentorder/cancel',
                                                    data: {
                                                        id: data.content[index].id
                                                    },
                                                    type: 'POST',
                                                    success: function (data) {
                                                        ConfirmedOrder(1, SEOval)
                                                    }
                                                })
                                            }
                                        }
                                    };
                                    $('body').ModalBox(QuCar);
                                }
                            })
                        } else {
                            val.PullDownAction['Default'] = {
                                name: '分配车辆',
                                action: function (e) {
                                    dispatchCar(data, index)
                                }
                            };
                            val.PullDownAction.data.push({
                                name: '销单',
                                action: function (e) {
                                    var QuCar = {
                                        data: {
                                            Title: '销单提示',
                                            Content: '你确定要销单吗？',
                                            OkChange: function () {
                                                var xiaodanOption = {
                                                    id: data.content[index].id
                                                };
                                                $.ajax({
                                                    url: ctx + '/rentorder/cancel',
                                                    data: xiaodanOption,
                                                    type: 'POST',
                                                    success: function (data) {
                                                        $('body').Overlays({
                                                            data: {
                                                                text: "销单成功！",
                                                                state: 'Ok'
                                                            }
                                                        });
                                                        ConfirmedOrder(1, SEOval)
                                                    }
                                                })
                                            }
                                        }
                                    };
                                    $('body').ModalBox(QuCar);
                                }
                            });
                            var AllotCar = $('<div class="AllotCarBut"></div>');
                            AllotCar.ActionButtons({
                                data: '分配车辆', onChange: function () {
                                    dispatchCar(data, index)
                                }
                            });
                            val.Car = AllotCar;
                            // console.log(val)
                        }
                        switch (data.content[index].isBackPrepayRent) {
                            case 0:
                                val.RentalStandard = '未交付';
                                val.PullDownAction.data.push({
                                    name: '交租车押金',
                                    action: function (e) {
                                        var prepayRentTime = '';
                                        var prepayRent = '';
                                        var prepayRentType = 1;
                                        var yajinjiluData = {
                                            data: {
                                                Title: '交租车押金',
                                                Content: '',
                                                OkChange: function (e,Remove) {
                                                    var reRentTime = '';
                                                    var huanche;

                                                    function Ajax() {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "押金记录录入成功") {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ConfirmedOrder(1, SEOval);
                                                                    xin();
                                                                    Remove()
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                    ConfirmedOrder(1,SEOval)
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    }

                                                    if (prepayRentType == 1) {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRentTime: prepayRentTime,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType,
                                                        };
                                                        if(!huanche.prepayRent==''&& !huanche.prepayRentTime==''){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    } else {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType,
                                                        };
                                                        if(huanche.prepayRent){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    }





                                                },
                                                CancelChange: function () {
                                                    $('body .datepicker').remove();
                                                }
                                            },
                                            OKHide:true
                                        };
                                        var ModContent = $('<div class="ModContent"></div>');
                                        var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>租车押金额度：</div></div>');
                                        var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                        Content.find('.YsInput').on('input', function () {
                                            prepayRent = $(this).val();
                                            if(prepayRent<0){
                                                prepayRent=0;
                                                $(this).val('');
                                            }
                                        });
                                        YSRows.append(Content);
                                        ModContent.append(YSRows);
                                        var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                        var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                        YSRowsType.append(Content2);
                                        ModContent.append(YSRowsType);
                                        var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                        var Content1 = $('<div class="RowsContent"></div>');
                                        var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                        var shijian=Date.parse(new Date())/1000;
                                        TimeInput.datetimepicker({
                                            format: "yyyy-mm-dd HH:ii",
                                            language: 'zh-CN',
                                            showMeridian: true,
                                            autoclose: true,
                                            todayBtn: true,
                                            startDate:$().Timestamp.TimestampDate(shijian)
                                        }).on('change', function () {
                                            var Titme = $(this).val();
                                            prepayRentTime = $().Timestamp.DateTimestamp(Titme);
                                        });
                                        Content1.append(TimeInput);
                                        TimeRows.append(Content1);
                                        ModContent.append(TimeRows);
                                        yajinjiluData.data.Content = ModContent;
                                        var rentCar = ModContent.find('.rentCarInput');
                                        for (var i = 0; i < rentCar.length; i++) {
                                            rentCar.eq(i).on('click', function () {
                                                switch ($(this).val()) {
                                                    case '预授权':
                                                        prepayRentType = 1;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'100','display': 'inline-block'});;
                                                        break;
                                                    case '现金':
                                                        prepayRentType = 0;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'-100','display': 'none'});
                                                        break;
                                                }
                                            })
                                        }
                                        $('body').ModalBox(yajinjiluData);
                                    }
                                });
                                break;
                            case 1:
                                val.RentalStandard = data.content[index].prepayRent;
                                break;
                            case 2:
                                val.RentalStandard = '已退还';
                                break
                        }
                        switch (data.content[index].isBackPeccancyForegift) {
                            case 0:
                                val.Prepayment = '未交付';
                                val.PullDownAction.data.push({
                                    name: '交违章押金',
                                    action: function (e) {
                                        var peccancyForegiftTime = '';
                                        var peccancyForegift = '';
                                        var peccancyForegiftType = 1;
                                        var yajinjiluData = {
                                            data: {
                                                Title: '交违章押金',
                                                Content: '',
                                                OkChange: function (e,Rmove) {
                                                    var reRentTime = '';
                                                    var huanche;


                                                    function Ajax() {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "押金记录录入成功") {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    xin();
                                                                    ConfirmedOrder(1, SEOval);
                                                                    Rmove()
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    });
                                                                    ConfirmedOrder(1, SEOval);
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    }
                                                    if (peccancyForegiftType == 1) {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            peccancyForegiftTime: peccancyForegiftTime,
                                                            peccancyForegift: peccancyForegift,
                                                            peccancyForegiftType: peccancyForegiftType,
                                                        };

                                                        if(!huanche.peccancyForegift<=0&&!huanche.peccancyForegiftTime==''){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    } else {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            peccancyForegift: peccancyForegift,
                                                            peccancyForegiftType: peccancyForegiftType,
                                                        };
                                                        if(!huanche.peccancyForegift<=0){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    }



                                                },
                                                CancelChange: function () {
                                                    $('body .datepicker').remove();
                                                }
                                            },
                                            OKHide:true
                                        };
                                        var ModContent = $('<div class="ModContent"></div>');
                                        var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>违章押金额度：</div></div>');
                                        var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                        Content.find('.YsInput').on('input', function () {
                                            peccancyForegift = $(this).val()
                                            if(peccancyForegift<0){
                                                peccancyForegift=0;
                                                $(this).val('0')
                                            }
                                        });
                                        YSRows.append(Content);
                                        ModContent.append(YSRows);
                                        var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                        var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                        YSRowsType.append(Content2);
                                        ModContent.append(YSRowsType);
                                        var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                        var Content1 = $('<div class="RowsContent"></div>');
                                        var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                        var shijian=Date.parse(new Date())/1000;
                                        TimeInput.datetimepicker({
                                            format: "yyyy-mm-dd HH:ii",
                                            language: 'zh-CN',
                                            showMeridian: true,
                                            autoclose: true,
                                            todayBtn: true,
                                            startDate:$().Timestamp.TimestampDate(shijian)
                                        }).on('change', function () {
                                            var Titme = $('body .CustomModalBox[custommodalboxlength="0"] .TimeInput').val();
                                            peccancyForegiftTime = $().Timestamp.DateTimestamp(Titme);
                                        });
                                        Content1.append(TimeInput);
                                        TimeRows.append(Content1);
                                        ModContent.append(TimeRows);
                                        yajinjiluData.data.Content = ModContent;
                                        var rentCar = ModContent.find('.rentCarInput');
                                        for (var i = 0; i < rentCar.length; i++) {
                                            rentCar.eq(i).on('click', function () {
                                                switch ($(this).val()) {
                                                    case '预授权':
                                                        peccancyForegiftType = 1;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'100','display': 'inline-block'});;
                                                        break;
                                                    case '现金':
                                                        peccancyForegiftType = 0;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'-100','display': 'none'});
                                                        break;
                                                }
                                            })
                                        }
                                        $('body').ModalBox(yajinjiluData);
                                    }
                                });
                                break;
                            case 1:
                                val.Prepayment = data.content[index].peccancyForegift;
                                break;
                            case 2:
                                val.Prepayment = '已退还';
                                break
                        }
                        switch (data.content[i].isPay) {
                            case 0:
                                val.payed = $('<span class="badge">未交付</span>');
                                break;
                            case 1:
                                val.payed = data.content[i].payed;
                                break;
                            case 2:
                                val.payed =data.content[i].payed;
                                break;
                            case 3:
                                val.payed = data.content[i].payed;
                                break;
                            case 4:
                                val.payed = '已结算';
                                break;
                        }
                        option.data.Tbody.push(val)
                    })(i)
                }
                var PagingMdOption = {
                    data: {
                        rows: limit,
                        nowrows: page,
                        Pages: '',
                        total: data.totalElements,
                        change: function (index) {
                            ConfirmedOrder(index, SEOval);
                        }
                    }
                };
                $('.ConfirmedOrder').find('.CustomOrder').remove();
                $('.ConfirmedOrder').parent().find('.PagingMdPagingMd').remove();
                $('.ConfirmedOrder').Order(option);
                $('.ConfirmedOrder').PagingMd(PagingMdOption);
            }
        });
    }

    ConfirmedOrder(1, SEOval);
    $(".Nav .SEO .SEOButton").on("click", function () {
        SEOval = $(".Nav .SEO  input").val();
        ConfirmedOrder(1, SEOval);
    });
    $(document).keyup(function (event) {
        switch (event.keyCode) {
            case 13:
                $(".Nav .SEO .SEOButton").click();
                break;
        }
    });
});